#include<bits/stdc++.h>
using namespace std;
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
const int N=2e5+5;
typedef vector<int> vi; 
#define pb push_back
#define all(x) x.begin(),x.end()
typedef long long ll;
typedef long double ld; 
typedef vector<int>  vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int main()
{
    int n,m;
    cin>>n>>m;
    vector<int>a(n),b(m);
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<m;i++){
        cin>>b[i];
    }
    sort(all(a));sort(all(b));
    int p=0,q=0;
    int res=INT_MAX;
    while(p<n && q<m){
        res=min(res,abs(a[p]-b[q]));
        if(a[p]>b[q]) q++;
        else p++;
    }
    cout<<res;
}